/**
 * name:        众筹页面头部
 * author:      wuwq & lyj
 * Time:        18/01/31
 * Copyright:   chinadangmai.com
 */
$(function(){
    $('head').append('<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">');
    var t=''
    t+='<div class="mod_head_wrap">'
    t+='<a class="mod_logo" href="/index.html"><img src="../../img/base/logo.png" alt=" logo"></a>'
    // t+='<div class="mod_search">'
    // // t+='<form class="search_form" action="">'
    // // t+='<div class="search_wrap">'
    // // t+='<input class="search_input" type="text" placeholder="请输入关键词">'
    // // t+='</div>'
    // // t+='</form>'
    // // t+='<div class="search_btn">'
    // // t+='<i class="search_btn_icon"></i>'
    // // t+='</div>'
    // // t+='<ul class="hot_search" id="hotSearch">'
    // // t+='</ul>'
    // t+='</div>'
    // t+='<div class="mod_info">'
    // t+='<a class="shopping_cart" href="../cart/cart.html"><i class="cart_icon"></i><span>购物车</span><em></em></a>'
    // t+='<a class="kefu_line" href="javascript:0;"><i class="tel_icon"></i><span>0592-6031-095</span></a>'
    // t+='</div>'
    t+='<div class="cart_tit" style="border-bottom:0">'
    t+='<ul style="width:760px;">'
    t+='<li class="active_01">'
    t+='<em>1</em>我的购物车'
    t+='</li>'
    t+='<li class="active" style="margin-left:108px">'
    t+='<em>2</em>确认订单'
    t+='</li>'
    t+='<li style="margin-left:120px">'
    t+='<em>3</em>付款'
    t+='</li>'
    t+='<li style="margin-left:120px">'
    t+='<em>4</em>支付成功'
    t+='</li>'
    t+='</ul>'
    t+='<div class="jindu"></div>'
    t+='</div>'
    t+='</div>'

var nav=''
nav+='<nav class="mod_nav">'
nav+='<div class="mod_nav_wrap">'
nav+='<div class="mod_serve">'
nav+='<div class="mod_submenu">'
nav+='<div style="font-weight:bold;">全部服务</div>'
nav+='<div class="mod_submenu" style="position: relative;">'
nav+='<ul class="mod_menu_list">'
nav+='<li class="mod_submenu" id="subMenuTop" style="width:200px;">'
nav+='<div class="mod_subment_tit"><i class="submenu_icon submenu_icon_01"></i><a href="javascript:;">品类采购</a></div>'
nav+='<ul class="mod_submenu_top" id="mod_submenu_top">'
    nav+='<li class="nav_1"><i class="nav_img1"></i><a href="/src/type/type_list.html?categoryId=4136&parentId=0" target="_blank">水果蔬菜</a></li>'
    nav+='<li class="nav_2"><i class="nav_img2"></i><a href="/src/type/type_list.html?categoryId=4137&parentId=0" target="_blank">粮油干货</a></li>'
    nav+='<li class="nav_3"><i class="nav_img3"></i><a href="/src/type/type_list.html?categoryId=4138&parentId=0" target="_blank">畜牧水产</a></li>'
    nav+='<li class="nav_4"><i class="nav_img4"></i><a href="/src/type/type_list.html?categoryId=4139&parentId=0" target="_blank">农副加工</a></li>'
    nav+='<li class="nav_5"><i class="nav_img5"></i><a href="/src/type/type_list.html?categoryId=4105&parentId=0" target="_blank">粮油副食</a></li>'
    nav+='<li class="nav_6"><i class="nav_img6"></i><a href="/src/type/type_list.html?categoryId=4106&parentId=0" target="_blank">零食干果</a></li>'
    nav+='<li class="nav_7"><i class="nav_img7"></i><a href="/src/type/type_list.html?categoryId=4107&parentId=0" target="_blank">茗茶名酒</a></li>'
    nav+='<li class="nav_8"><i class="nav_img8"></i><a href="/src/type/type_list.html?categoryId=4108&parentId=0" target="_blank">3C小家电</a></li>'
    nav+='<li class="nav_9"><i class="nav_img9"></i><a href="/src/type/type_list.html?categoryId=4109&parentId=0" target="_blank">家居家纺</a></li>'
    nav+='<li class="nav_10"><i class="nav_img10"></i><a href="/src/type/type_list.html?categoryId=4110&parentId=0" target="_blank">商务礼品</a></li>'
nav+='</ul>'
nav+='</li>'
//nav+='<li class="mod_submenu">'
//nav+='<div class="mod_subment_tit"><i class="submenu_icon submenu_icon_02"></i><a href="javascript:;" class="kfing">场景定制</a></div>'
//nav+='<dl>'
//nav+='<dd>'
//nav+='<a href="javascript:;" class="kfing">博饼礼包</a>'
//nav+='<a href="javascript:;" class="kfing">年终礼包</a>'
//nav+='<a href="javascript:;" class="kfing">中秋礼包</a>'
//nav+='<a href="javascript:;" class="kfing">五一礼包</a>' 
//nav+='</dd>'
//nav+='</dl>'
//nav+='</li>'
//nav+='<li class="mod_submenu">'
//nav+='<div class="mod_subment_tit"><i class="submenu_icon submenu_icon_03"></i><a href="/case/case.html?type=1" target="_blank">特色出行</a></div>'
//nav+='<dl>'
//nav+='<dd>'
//nav+='<a href="/case/case_detail.html?T=1&Id=275" target="_blank">云顶温泉</a>'
//nav+='<a href="/case/case_detail.html?T=1&Id=278" target="_blank">长泰漂流</a>'
//nav+='<a href="/case/case_detail.html?T=1&Id=268" target="_blank">南靖土楼</a>'
//nav+='<a href="/case/case_detail.html?T=1&Id=279" target="_blank">志闽团建</a>'
//nav+='</dd>'
//nav+='</dl>'
//nav+='</li>'
// nav+='<li class="mod_submenu">'
// nav+='<div class="mod_subment_tit"><i></i><a href="javascript:;" class="kfing">工会资讯</a></div>'
// nav+='</li>'
//nav+='<li class="mod_submenu">'
//nav+='<div class="mod_subment_tit"><i class="submenu_icon submenu_icon_04"></i><a href="javascript:;" class="kfing">企业定制</a></div>'
//nav+='<dl>'
//nav+='<dd class="fw">'
//nav+='<a href="/service/purchase.html?type=1">采购需求</a>'
//nav+='<a href="/service/purchase.html?type=2">服务需求</a>'
//nav+='</dd>'
//nav+='</dl>'
//nav+='</li>'
nav+='</ul>'
//nav+='<div class="submenu_pop" id="submenu_pop">'
//nav+='<ul class="pop_top" id="pop_top"></ul>'
//nav+='<ul class="pop_list" id="pop_list"></ul>'
//nav+='</div>'
nav+='</div>'
nav+='</div>'
nav+='</div>'
nav+='<ul class="mod_menu">'
nav+='<li><a href="/index.html">首页</a></li>'
// nav+='<li><a href="javascript:;" class="kfing">节日礼品</a></li>'
//nav+='<li><a href="/case/case.html?type=1" target="_blank">特色出行</a></li>'
// nav+='<li><a href="/crowdfunding/index.html" target="_blank">企业众筹</a></li>'
//nav+='<li><a href="/case/case.html?type=0" target="_blank">成功案例</a></li>'
// nav+='<li><a href="javascript:;" class="kfing">积分商城</a></li>'
//nav+='<li><a href="/about/about_us.html">关于 </a></li>'
nav+='</ul>'
nav+='<div class="mod_login">'
nav+='<div class="yes_or_no"><a class="login" href="/login/login.html?type=2">登录</a>'
nav+='<span>|</span>'
nav+='<a class="register" href="/login/register.html">注册</a></div>'
nav+='</div>'
nav+='</div>'
nav+='</nav>'
var hover=''

var scri=''
var scri2=''
var scri3=''
var scri4=''
var scri6=''
scri+='<script id="tpl" type="text/html">'
scri+='{{ for(var i = 0; i < list.length; i++) { }}'
scri+='<li><a href="/type/type_list.html?categoryId={{=list[i].categoryId}}&parentId={{=list[i].parentId}}" target="_blank">{{=list[i].name}}</a></li>'
scri+='{{ } }}'
scri+='</script>'
scri2+='<script id="tplTwo" type="text/html">'
scri2+='{{ for(var i = 0; i < listTwo.length; i++) { }}'
scri2+='<li><a href="/type/type_list.html?categoryId={{=listTwo[i].categoryId}}&parentId={{=listTwo[i].parentId}}" target="_blank">{{=listTwo[i].name}}&nbsp;&nbsp;></a></li>'
scri2+='{{ } }}'     
scri2+='</script>'
            
scri3+='<script id="tplChild" type="text/html">'
scri3+='{{ for(var a = 0; a < tplChildList.length; a++) { }}'
scri3+='<li>'
scri3+='<a class="menu" href="/type/type_list.html?categoryId={{=tplChildList[a].categoryId}}&parentId={{=tplChildList[a].parentId}}" target="_blank">'
scri3+='{{=tplChildList[a].name}}'
scri3+='</a>'
scri3+='<ul class="sub_menu_list" id="menu{{=tplChildList[a].index}}">'
scri3+='</ul>'
scri3+='</li>'
scri3+='{{ } }}'
scri3+='</script>'
scri4+='<script id="subMenuTpl" type="text/html">'
scri4+='{{ for(var i = 0; i < subMenuList.length; i++) { }}'
scri4+='<li>'
scri4+='<a href="/type/type_list.html?categoryId={{=subMenuList[i].categoryId}}&parentId={{=subMenuList[i].parentId}}" target="_blank">'
scri4+='{{=subMenuList[i].childName}}'
scri4+='</a>'
scri4+='</li>'
scri4+='{{ } }} '
scri4+='</script>'
// 热门搜索
scri6+='<script id="hotSearchTpl" type="text/html">'
scri6+='{{ for(var i = 0; i < hotSearchList.length; i++) { }}'
scri6+='<li>'
scri6+='<a href="/search/search_list.html?keyword={{=hotSearchList[i].name}}" target="_blank">'
scri6+='{{=hotSearchList[i].name}}'
scri6+='</a>'
scri6+='</li>'
scri6+='{{ } }} '
scri6+='</script>'
$('.mod_head').append(t)
$('.mod_head').after(nav)
$('body').append(hover)
$('body').append(scri)
$('body').append(scri2)
$('body').append(scri3)
$('body').append(scri4)
$('body').append(scri6)
function s(){
    var searchIup = $(".search_input").val(); 
    function removeAllSpace(str) {
        return str.replace(/\s+/g, "");
       }
    if(removeAllSpace(searchIup)==""){  
        tc("请输入关键词"); 
        $(".search_input").val('') 
        return;  
    }
    else{
        var url = "/src/search/search_list.html?keyword="+searchIup;
        window.location.href=url;
    }
}

$(".search_btn").click(function(){
    s()
});
// 回车事件
$(".search_input").keydown(function (e) {  
    if (e.which == 13) {  
        $('.search_btn').trigger("click");
        return false; 
    }  
});  
    // 首页左侧类目
    $.ajax({
        type:'post',
        url:new_url+'shop/index/getCategoryList',
        dataType:'json',
        success:function(response){ 
            getCategoryList_one(response);
            getCategoryList_two(response);
        }
    });
    function getCategoryList_one(response){
//      var tpl = $('#tpl').html();
//      for (var i=0; i<4; i++){
//          var t=template(
//              tpl, {
//                  list: [{
//                      name:response.data[i].name,
//                      categoryId:response.data[i].categoryId,
//                      parentId:response.data[i].parentId
//                  }]
//              }
//          );
//          $('#mod_submenu_top').append(t); 
			for (var i=0; i<response.data.length; i++){
            var t=template(
                tpl, {
                    list: [{
                        name:response.data[i].name,
                        categoryId:response.data[i].categoryId,
                        parentId:response.data[i].parentId
                    }]
                }
            );
//          $('#mod_submenu_top').append(t); 
        }
        var tplTwo = $('#tplTwo').html();
        for (var i=0; i<4; i++){
            var tTwo=template(
                tplTwo, {
                    listTwo: [{
                        name:response.data[i].name,
                        categoryId:response.data[i].categoryId,
                        parentId:response.data[i].parentId
                    }]
                }
            );
            $('.pop_top').append(tTwo); 
        }
        var tplChild = $('#tplChild').html();
        for (var k=0; k<response.data.length; k++){
            var tplChildCont=template(
                tplChild, {
                    tplChildList: [{
                        index:k+1,
                        name:response.data[k].name,
                        categoryId:response.data[k].categoryId,
                        parentId:response.data[k].parentId
                    }]
                }
            );
            $('#pop_list').append(tplChildCont); 
        }
    }
    
    function getCategoryList_two(response){
        var subMenuTpl = $("#subMenuTpl").html();
        for (var s=0; s<response.data.length; s++){
            for(var j=0;j<response.data[s].child.length;j++){
                var subMenucont=template(
                    subMenuTpl, {
                        subMenuList: [{
                                childName:response.data[s].child[j].name,
                                categoryId:response.data[s].child[j].categoryId,
                                parentId:response.data[s].child[j].parentId
                        }]
                    }
                );
                var k = "#menu"+(s+1);
                $(k).append(subMenucont); 
            }
        }
    }

    $(".kfing").click(function(){
        kf();
    })
    // 热门搜索
    $.ajax({
        type:'post',
        url:new_url+'shop/search/getHotSearch',
        dataType:'json',
        success:function(e){
            var strs=e.data.value.split(",");
            var hotSearch = new Array();
            var hotSearchTpl = $('#hotSearchTpl').html();
            for(var i in strs){
                var hotSearchCont=template(
                    hotSearchTpl, {
                        hotSearchList: [{
                            name:strs[i]
                        }]
                    }
                );
                $('#hotSearch').append(hotSearchCont); 
            }
        }
    });
    $('#subMenuTop, #submenu_pop').mouseover(function(){
        $("#subMenuTop").addClass('active');
        $('#submenu_pop').css("display","block");
        $('#mod_submenu_top').css('border-bottom','rgba(255,255,255,.9) solid 1px')
    })
    $('#subMenuTop, #submenu_pop').mouseout(function(){
        $("#subMenuTop").removeClass('active');
        $('#submenu_pop').css("display","none");
        $('#mod_submenu_top').css('border-bottom','rgba(204,204,204,0.5) solid 1px')
    });
    
})

$(function(){
    if($.cookie('user')!=''&&$.cookie('user')!=null){
        
        }
        else{
            setTimeout(function(){
                $('.fw').last().find('a').attr('href','/src/login/login.html?type=2')
            },300)
            
            $('.shopping_cart').attr('href','javascript:0;');
            $('.shopping_cart').click(function(){
                tc('请登录')
                setTimeout(function(){
                    window.location.href='/src/login/login.html?type=2'
                },300)
            })
        }
})